package com.yuhan.common.base;

import com.yuhan.common.utils.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @program: yunpi-credit-parent
 * @description: 分页
 * @author: hejing
 * @create: 2019-08-03 14:32
 **/

@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
    List<T> findAll(final Page page, final String hql);

    List<T> findAll(final Page page, final String sql, Class<T> clazz);

    List<Map> findMap(final Page page, final String hql);

    @Override
    @Transactional
    @Modifying
    @Query(value = "UPDATE #{#entityName} t SET t.delFlag = 1 WHERE t.id = ?1")
    void deleteById(ID id);
}
